<template>
	<view class="lottie-bg">
		<!-- <u-loading-page :loading="true" image="https://qny.yijiumy.com/20240320154503-20240320154058.png" icon-size="44" fontSize="14" color="#999999" loadingText="加载中..."></u-loading-page> -->
		<!-- <view id="lottie">
			
		</view> -->
		<!-- ref：唯一ref  timedown:开屏广告秒数  imageUrl：图片地址  advertClick：广告图点击 -->
		<!-- <cc-advertView ref="ccAdvert" :timedown="5" :imageUrl="`http://qny.yijiumy.com/20240316155008-20240316154920.jpg`" @advertClick="advertClick" @endAdvert="endAdvert"></cc-advertView> -->
		<image src="/static/img/119.png" style="width: 90px; margin-top: -600rpx;" mode="widthFix" />
	</view>
</template>

<script>
	import {
		mapActions
	} from "vuex";
	import cookie from "@/utils/store/cookie";
	import {
		handleQrCode,
		handleUrlParam,
		getCurrentPageUrlWithArgs
	} from "@/utils";

	export default {
		name: "Loading",
		data() {
			return {};
		},
		onLoad(options) {
			// 初始化广告图
			// this.$refs.ccAdvert.initAdvert();
			console.log("onLoad加载：通过太阳码识别进入，且携带参数的spread")
			console.log(options)
			if (Object.keys(options).length) {
				if (options.scene) cookie.set("spread", options.scene);
				if (options.wxType) cookie.set("wxType", options.wxType);
			} else {
				cookie.remove("wxType");
			}
		},
		onShow() {
			var url = handleQrCode();
			if (!url) {
				url = handleUrlParam(getCurrentPageUrlWithArgs())
			}
			// 判断是否是分销
			if (url) {
				let urlSpread = parseInt(url.spread);
				if (urlSpread) {
					cookie.set("spread", urlSpread);
				}
			}
			if (this.$deviceType == "app" || this.$deviceType == "weixinh5") {
				this.$yrouter.reLaunch({
					path: "/pages/launch/index"
				});
				return;
			}
			console.log(this.$store)
			if (this.$store && this.$store.getters.token) {
				// 如果token存在，直接进行进页面
				console.log('登录状态存在，直接进页面')
				this.toLaunch();
				return;
			} else {
				this.$yrouter.reLaunch({
					path: "/pages/launch/index"
				});
			}
			// 微信小程序
			// if (this.$deviceType == "routine") {
			// 	this.$yrouter.reLaunch({
			// 		path: "/pages/launch/index"
			// 	});
			// 	return;
			// }
		},
		methods: {
			...mapActions(["changeAuthorization"]),
			toLaunch() {
				this.changeAuthorization(false);
				let redirect = cookie.get('redirect').replace(/\ /g, '')
				console.log(redirect)
				if (redirect && redirect.indexOf('/pages') != -1) {
					console.log(redirect.split('/pages')[0])
					console.log(redirect.split('/pages')[1])
					if(redirect.split('/pages')[0]) {
						this.$yrouter.reLaunch({
							path: "/pages/launch/index"
						});
					} else {
						this.$yrouter.replace({
							path: '/pages' + redirect.split('/pages')[1],
						});
					}
					
					cookie.remove('redirect');
				} else {
					this.$yrouter.reLaunch({
						path: "/pages/launch/index"
					});
				}
			},
			// advertClick(e) {
			// 	this.$yrouter.reLaunch({
			// 		path: "/pages/launch/index"
			// 	});
			// },
			// endAdvert() {
			// 	this.$yrouter.reLaunch({
			// 		path: "/pages/launch/index"
			// 	});
			// }
		}
	};
</script>

<style scoped lang="less">
	.lottie-bg {
		position: fixed;
		left: 0;
		top: 0;
		background-color: #fff;
		width: 100%;
		height: 100%;
		z-index: 999;
		display: -webkit-flex;
		display: flex;
		-webkit-align-items: center;
		align-items: center;
		-webkit-justify-content: center;
		justify-content: center;
		text-align: center;
	}

	#lottie {
		// width: 35%;
		width: 100%;
		height: 100%;
		display: block;
		overflow: hidden;
		transform: translate3d(0, 0, 0);
		margin: auto;
	}
</style>